﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Camc.OutsourceProcession.ManufacturingEquipment.Dto;
using Camc.OutsourceProcession.Printer;
using Camc.OutsourceProcession.Printer.Dto;

namespace Camc.OutsourceProcession.ManufacturingEquipment
{
	public class EquipmentAppService : CrudAppService<Equipment, EquipmentDto, long, GetAllEquipmentInput,
		CreateEquipment, UpdateEquipment>, IEquipmentAppService
	{
		private readonly IPrintEquipmentAppService _printEquipmentAppService;
		public EquipmentAppService(IRepository<Equipment, long> repository, IPrintEquipmentAppService printEquipmentAppService) : base(repository)
		{
			_printEquipmentAppService = printEquipmentAppService;
		}

		public List<ComboboxItemDto> GetComboboxItemForEquipmentType()
		{
			
			var allType = new List<ComboboxItemDto>();

			foreach (var value in Enum.GetValues(typeof(EquipmentType)))
			{
				var type = new ComboboxItemDto(((int)(value)).ToString(), value.ToString());
			
				allType.Add(type);
			}

			return allType;
		}

		public void Print(long equipmentId)
		{
			var myPrinterSn = _printEquipmentAppService.GetMyPrinterSN();
			var equipmentName = Repository.Get(equipmentId).DisplayName;
			PrintForEquipment.Print(myPrinterSn, equipmentId.ToString(), equipmentName);
		}
	}
}
